#include <iostream>
#include <string>
#include <filesystem>
namespace fs = std::filesystem;

int main(int argc, char* argv[]) {
    if (argc != 3) {
        std::cerr << "Usage: " << argv[0] << " STRING DIRECTORY" << std::endl;
        return 1;
    }
    std::string to_remove = argv[1];
    fs::path dir_path = argv[2];
    if (!fs::exists(dir_path) || !fs::is_directory(dir_path)) {
        std::cerr << "Error: Invalid directory path" << std::endl;
        return 1;
    }
    int total_files = 0;
    int renamed_files = 0;
    for (const auto& entry : fs::directory_iterator(dir_path)) {
        if (entry.is_regular_file()) {
            total_files++;
            fs::path old_path = entry.path();
            std::string old_filename = old_path.filename().string();
            size_t pos = old_filename.find(to_remove);
            if (pos != std::string::npos) {
                renamed_files++;
                std::string new_filename = old_filename.substr(0, pos) + old_filename.substr(pos + to_remove.length());
                fs::path new_path = old_path.parent_path() / new_filename;
                fs::rename(old_path, new_path);
            }
        }
    }
    std::cout << "String to remove: " << to_remove << std::endl;
    std::cout << "Total files processed: " << total_files << std::endl;
    std::cout << "Files renamed: " << renamed_files << std::endl;
    return 0;
}
